﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace TBM
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            GlobalFilters.Filters.Add(new Filters.ActionFilters());
        }


        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            //filters.Add(new Filters.ExceptionFillters());
            filters.Add(new Filters.ActionFilters());
        }


        //protected void Application_Error(object sender, EventArgs e)
        //{
        //    Exception exception = Server.GetLastError();
        //    Type exceptionType = exception.GetType();
        //    RouteData route = new RouteData();
        //    bool isException = false;
        //    Response.Clear();

        //    route.Values.Add("controller", "JsRsp");

        //    // 远程服务未能正确响应
        //    if (typeof(InvalidOperationException) == exceptionType)
        //    {
        //        route.Values.Add("action", "Error");
        //        route.Values.Add("errorCode", 3);
        //        isException = true;
        //    }

        //    if (isException)
        //    {
        //        Server.ClearError();
        //        IController errorController = new TBMSite.Controllers.JsRspController();
        //        errorController.Execute(new RequestContext(new HttpContextWrapper(Context), route));
        //    }
        //}
    }
}